package com.jjty.dataGenerator.utils;

import lombok.Data;

import javax.servlet.http.HttpServletRequest;
import java.net.InetAddress;
import java.net.UnknownHostException;

public class OtherUtils {



    /**
     * 获取请求ip
     * @param request
     * @return
     */
    public static String getExternalIP(HttpServletRequest request) {
        String remoteAddr = "";
        try {
            remoteAddr = request.getHeader("X-FORWARDED-FOR");
            if (remoteAddr == null || "".equals(remoteAddr)) {
                remoteAddr = request.getRemoteAddr();
                if ("127.0.0.1".equals(remoteAddr)) {
                    remoteAddr = InetAddress.getLocalHost().getHostAddress();
                }
            }
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        return remoteAddr;
    }


    @Data
    public static class IpRegion{

        /**
         * success 成功
         */
        private String status;

        /**
         * 国家
         */
        private String country;

        /**
         * 省
         */
        private String regionName;

        /**
         * 市
         */
        private String city;

    }


}